package com.comac.print.component.app.utils;


import freemarker.cache.URLTemplateLoader;
import org.apache.commons.lang3.StringUtils;

import java.net.MalformedURLException;
import java.net.URL;
/**
 * 远程URL的形式实现模板加载
 *
 */
public class RemoteTemplateLoader extends URLTemplateLoader{
   // 远程模板存储文件的路劲
    private String remorePath;
    public RemoteTemplateLoader(String remorePath){
        if(StringUtils.isBlank(remorePath)){
          throw new IllegalArgumentException("remorePath is null");
        }
      this.remorePath = canonicalizePrefix(remorePath);
    }

    @Override
    protected URL getURL(String name) {
        String fullPath = this.remorePath + name;
        fullPath = fullPath.replace("_zh","").replace("_CN","").replace("_en","").replace("_US","");
        URL url = null;
        try {
            url = new URL(fullPath);
        }catch (MalformedURLException e ){
           e.printStackTrace()  ;
        }
        return url;
    }
}